package com.storeroompda.ui.login;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.shelwee.update.UpdateHelper;
import com.storeroompda.App;
import com.storeroompda.R;
import com.storeroompda.base.views.BaseActivity;
import com.storeroompda.entity.BillCodeControl;
import com.storeroompda.entity.BillCodeInfo;
import com.storeroompda.tool.CheckVerisonUtils;
import com.storeroompda.tool.FileControl;
import com.storeroompda.ui.config.ConfigActivity;
import com.storeroompda.ui.main.MainActivity;
import com.storeroompda.ui.scanfconfig.ScanfConfigActivity;
import com.storeroompda.utils.Utils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity<LoginModel, LoginView, LoginPresent> implements LoginView {
    private String tag="LoginActivity";
    @BindView(R.id.iv_title_left)
    ImageView ivTitleLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_ver)
    TextView tvVer;
    @BindView(R.id.ivu)
    ImageView ivu;
    @BindView(R.id.login_id)
    EditText loginId;
    @BindView(R.id.ivp)
    ImageView ivp;
    @BindView(R.id.login_p)
    EditText loginP;
    @BindView(R.id.cb_rp)
    CheckBox cbRp;
    @BindView(R.id.loginbt)
    Button loginbt;
    @BindView(R.id.configbt)
    Button configbt;
    @BindView(R.id.scanfbt)
    Button scanfbt;
    boolean flag=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        tvTitle.setText("登录");
        tvVer.setText("版本号:v"+CheckVerisonUtils.getVersionName(this));

        UpdateHelper updateHelper = new UpdateHelper.Builder(this)
                .checkUrl(App.sSharedPreferences.getString(Utils.addresskey, "") )
                .isAutoInstall(true) //设置为false需在下载完手动点击安装;默认值为true，下载后自动安装。
                .build();
        updateHelper.check();

        flag=App.sSharedPreferences.getBoolean(Utils.urpkey,false);
        if(flag)
        {
            cbRp.setChecked(flag);
            loginId.setText(App.sSharedPreferences.getString(Utils.unamekey,""));
            loginP.setText(App.sSharedPreferences.getString(Utils.upasskey,""));
        }
    }

    @Override
    public LoginModel createModel() {
        return new LoginModelImpl();
    }

    @Override
    public LoginView createView() {
        return this;
    }

    @Override
    public LoginPresent createPresenter() {
        return new LoginPresent();
    }

    @Override
    public void login() {

    }

    @OnClick({R.id.iv_title_left, R.id.cb_rp, R.id.loginbt, R.id.configbt, R.id.scanfbt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_title_left:
                finish();
                break;
            case R.id.cb_rp:
                flag=!flag;
                break;
            case R.id.loginbt:
                if(App.sSharedPreferences.getInt(Utils.wllkey,0)==0)
                {
                    showMsg("请先进行扫描配置");
                    return;
                }
                intentToActivityWithoutParameter(this, MainActivity.class);
                break;
            case R.id.configbt:
                intentToActivityWithoutParameter(this, ConfigActivity.class);
                break;
            case R.id.scanfbt:
                intentToActivityWithoutParameter(this, ScanfConfigActivity.class);
                break;
        }
    }
}
